//
//  DWThemeTabBar.swift
//  DWSwift
//
//  Created by GDL on 2025/6/20.
//

import Foundation
import SwiftUI

struct DWThemeTabBar: View {
    @Binding var selectedTab: DWThemeTab
    let tabs: [DWThemeTab]
    @Environment(\.colorScheme) private var colorScheme // 监听主题变化
    let action: (_ tab:DWThemeTab) -> Void
    // 动态颜色计算
    private var bgColor: Color { Color("TabBackground") }
    private var iconColor: Color { Color("TabIcon") }
    private var activeColor: Color { Color("TabActive") }
    
    var body: some View {
        HStack(spacing: 0) {
            ForEach(tabs) { tab in
                Button() {
                    action(tab)
                } label: {
                    VStack(spacing: 4) {
                        Image(systemName: tab.icon)
                            .symbolVariant(selectedTab == tab ? .fill : .none)
                            .foregroundStyle(
                                selectedTab == tab ? activeColor : iconColor
                            )
                        Text(tab.title)
                            .font(.system(size: 12))
                            .foregroundStyle(
                                selectedTab == tab ? activeColor : iconColor
                            )
                    }
                    .frame(maxWidth: .infinity)
                    .padding(.vertical, 8)
                }
            }
        }
        .background(bgColor) // 背景色 + 投影
        .ignoresSafeArea(.all, edges: .bottom) // 贴合底部安全区
    }
}


